<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="thx" uri="/thx-tags"%>
<style>
.form-horizontal .form-group {
	margin-right: 0px;
	margin-left: 0px;
}
</style>

<form id="user-form" name="ui-adminlte-form" class="form-horizontal"
	data-toggle="validator" role="form" method="post"
	container = "#user-list"
	action="${pageContext.request.contextPath}/user/user!save.action"
	forward-action="${pageContext.request.contextPath}/user/user!list.action">
	<s:token></s:token>
	<input name="id" value="${entity.userId }" type="hidden"/>
	<input name="message" value="${message}" type="hidden"/>
	<c:forEach items='${entity.roles}' var="role">
		<input name="roleId" value="${role.roleId}" type="hidden"/>
	</c:forEach>

	<div id="commons">
		<div class="row">
			<div class="form-group col-sm-6">
				<label>用户名 </label>
					<input type="text" name="entity.userName" value="${entity.userName}" class="form-control required"
						remote="${pageContext.request.contextPath}/user/user!checkUserName.action?id=${entity.userId}"
						placeholder="输入用户名"/>
			</div>
			<div class="form-group col-sm-6">
				<label>姓名 </label>
					<input type="text" name="entity.realName" value="${entity.realName}"
					class="form-control required" placeholder="输入姓名"/>
			</div>
		</div>
		<div class="row">
			<div class="form-group col-sm-6">
				<label>手机号 </label>
					<input type="text" name="entity.mobilePhone" value="${entity.mobilePhone}"
					 class="form-control required isMobile"
					remote="${pageContext.request.contextPath}/user/user!checkMobilePhone.action?id=${entity.userId}"
					placeholder="输入手机号"/>
			</div>
			<div class="form-group col-sm-6">
				<label>邮箱 </label>
					<input type="text" name="entity.email" value="${entity.email}"
					class="form-control required email"
					remote="${pageContext.request.contextPath}/user/user!checkEmail.action?id=${entity.userId}"
					placeholder="输入邮箱"/>
			</div>
		</div>
		<div id="setPwdDiv" class="row">
			<div class="form-group col-sm-6">
				<label>设置密码</label>
					<input type="password" id="password" name="entity.password"
					class="form-control required passwordCheck" placeholder="输入密码"/>
			</div>
			<div class="form-group col-sm-6">
				<label>确认密码</label>
					<input type="password" name="repassword" equalTo="#password"
					class="form-control required" placeholder="确认密码"/>
			</div>
		</div>
		<div class="row">
			<div class="form-group col-sm-6">
				<label>选择角色</label>
				<div class="btn-group" style="width:100%">
					<c:forEach items='${rolelist}' var="role" varStatus="row">
						<span style="float:left;margin-right:5px">
							<input type="checkbox" name="roleIds" value="${role.roleId}">${role.roleName}
						</span>
					</c:forEach>
				</div>
			</div>
			<div class="form-group col-sm-6">
				<label>所属部门</label>
				<div>
					<thx:select name="deptId" type="dep" value="${deptId }"></thx:select>
				</div>
			</div>
		</div>
		<%@include file="/pages/exproperty/expropertyInput2Column.jsp"%>
	</div>
	<div id="resetPwdDiv" class="row">
		<div class="form-group col-sm-6">
			<label>输入新密码</label>
				<input type="password" id="newpassword" name="entity.password"
				class="form-control required passwordCheck" placeholder="输入新密码"/>
		</div>
		<div class="form-group col-sm-6">
			<label>确认新密码</label>
				<input type="password" name="renewpassword" equalTo="#newpassword"
				class="form-control required" placeholder="确认新密码"/>
		</div>
	</div>
</form>

<script>
$(function() {
	form.init();

	var message='${message}';
	var userId ='${entity.userId}';
	if(message=='systemReset'){//管理员设置密码
		$('#commons').hide();
		$('#commons').remove();
	}else if(userId==''){//新增用户
		$('#resetPwdDiv').hide();
		$('#newpassword').disabled="disabled";
		$('#resetPwdDiv').remove();
	}else{//修改用户
		$('#setPwdDiv').hide();
		$('#resetPwdDiv').hide();
		$('#password').disabled="disabled";
		$('#newpassword').disabled="disabled";
		$('#setPwdDiv').remove();
		$('#resetPwdDiv').remove();
	}
	

	if(userId != ''){
		var roleSelect = $('input[name="roleIds"]');
		var roleId = document.getElementsByName("roleId");
		for(var i=0; i < roleSelect.length; i++){
			for(var j=0; j < roleId.length; j++){
				if(roleSelect[i].value == roleId[j].value){
					roleSelect[i].checked = "checked";
				}
			}
		}
	}
	
	icheckPlugin.init($('input'));
	
	$("select[name='deptId']").attr("class","form-control").attr("style","width:200px");
});
</script>